<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../lib/vue.js"></script>
</head>
<body>
    <div id="box">
        <!-- 在事件中不加()会得到事件对象 -->
        <!-- <input type="text" @input="handleInput">  -->
        <input type="text" v-model="myText" />
        <button @click="handleClick()">add</button>
        <div v-if="dataList.length===0">代办事项空空</div>
        <ul>
            <li v-for="(data, index) in dataList">
                {{data}}
                <button @click="handleDel(index)">delete</button>
            </li>
        </ul>
    </div>

    <script>
        new Vue({
            el:"#box",
            data: {
                myText: "",
                dataList:[]
            },
            methods: {
                handleClick() {
                    console.log("add + ", this.myText);
                    this.dataList.push(this.myText);
                    this.myText = "";
                },
                handleDel(index) {
                    this.dataList.splice(index, 1);
                }
            }
        })
    </script>
</body>
</html>